package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.SportsKnowledgeDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.SportsKnowledge;
import com.itheima.service.SportsKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service(interfaceClass = SportsKnowledgeService.class)
@Transactional
public class SportsKnowledgeServiceImpl implements SportsKnowledgeService {
    @Autowired
    private SportsKnowledgeDao sportsKnowledgeDao;

    public void add(List<SportsKnowledge> list) {
        if(list != null && list.size()>0){
            for (SportsKnowledge sportsKnowledge : list) {
                sportsKnowledgeDao.add(sportsKnowledge);
            }
        }
    }

    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<SportsKnowledge> page = sportsKnowledgeDao.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    public SportsKnowledge findById(Integer id) {
        return sportsKnowledgeDao.findById(id);
    }

    public void edit(SportsKnowledge sportsKnowledge) {
        sportsKnowledgeDao.edit(sportsKnowledge);
    }

    public void delete(Integer id) {
        sportsKnowledgeDao.delete(id);
    }
}
